<template>
  <div>
    <el-card>
      <h3>用户管理</h3>
      <div class="search">
        <el-form :model="form" label-width="120px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="Activity name">
                <el-input v-model="form.name" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="Activity zone">
                <el-select
                  v-model="form.region"
                  placeholder="please select your zone"
                >
                  <el-option label="Zone one" value="shanghai" />
                  <el-option label="Zone two" value="beijing" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="Activity form">
                <el-input v-model="form.desc" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>
                <el-button type="primary" @click="onSubmit">搜索</el-button>
                <el-button>重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="table">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="name" label="Name" width="180" />
          <el-table-column prop="age" label="age" />
          <el-table-column prop="address" label="Address" />
          <el-table-column prop="date" label="Date" width="180" />
          <el-table-column label="操作">
            <template #default="{ row }">
              <el-button type="primary" link @click="handleDetails(row)"
                >详情</el-button
              >
              <el-button type="primary" link @click="dialogVisible = true"
                >新增</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>

    <el-dialog v-model="dialogVisible" title="Tips" width="30%" @close="close">
      <span>
        <el-input v-model="obj.input" placeholder="Please input" />
      </span>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">Cancel</el-button>
          <el-button type="primary" @click="dialogVisible = false">
            Confirm
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import { useRoute, useRouter } from "vue-router";

const dialogVisible = ref(false);

const route = useRoute();
const router = useRouter();

const form = reactive({
  name: "",
  region: "",
  date1: "",
  date2: "",
  delivery: false,
  type: [],
  resource: "",
  desc: "",
});

const obj: any = ref({
  input: "",
});

const close = () => {
  obj.value = {};
};

const onSubmit = () => {
  console.log("submit!");
};

const tableData = [
  {
    id: 1,
    name: "Tom",
    age: "30",
    date: "2016-05-03",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    id: 2,
    name: "Tom",
    age: "24",
    date: "2016-05-02",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    id: 3,
    name: "Tom",
    age: "16",
    date: "2016-05-04",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    id: 4,
    name: "Tom",
    age: "19",
    date: "2016-05-01",
    address: "No. 189, Grove St, Los Angeles",
  },
];

const handleDetails = (row: any) => {
  console.log(row);
  const { id } = row;
  router.push({
    name: "systemDetails",
    params: { id },
  });
};
</script>

<style scoped lang="scss">
.search {
  margin: 20px 0;
}
</style>
